package com.itcv.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticSearchConfig {

    @Value("${elasticsearch.host}")
    private String host;
    @Value("${elasticsearch.port}")
    private Integer port;


   @Bean
    public ElasticsearchClient ElasticsearchClient() {
       RestClientBuilder builder = RestClient.builder(
               new HttpHost(host, port));
       ElasticsearchTransport transport = new RestClientTransport(builder.build(), new JacksonJsonpMapper());
       return new ElasticsearchClient(transport);
    }

}
